package com.cmbchina.yummy.mc.web.util;

import java.util.Date;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Map.Entry;

import com.pactera.dipper.core.Message;
import com.pactera.dipper.core.bean.Store;
import com.pactera.dipper.core.factory.FaultFactory;
import com.pactera.dipper.core.factory.IdGenerateFactory;
import com.pactera.dipper.core.factory.MessageFactory;
import com.pactera.dipper.core.utils.Constants.ResponseCode;
import com.pactera.dipper.utils.common.UUIDGenerator;

public abstract class MessageUtil {

	@SuppressWarnings("unchecked")
	public static Message getMessageInfo(Map<String, ?> parameterMap) {
		Message message = MessageFactory.create(IdGenerateFactory.generateId(), MessageFactory.createSimpleMessage(),
				MessageFactory.createSimpleMessage(new HashMap<String, Object>(), new HashMap<String, Object>()),
				FaultFactory.create(ResponseCode.SUCCESS, "success"), new LinkedList<Store>());

		Map<String, Object> map = (Map<String, Object>) message.getTarget().getBodys();

		map.put("sysDate", new Date());
		map.put("sysSeq", UUIDGenerator.randomUUID());

		if (parameterMap != null) {
			for (Entry<String, ?> entry : parameterMap.entrySet()) {
				map.put(entry.getKey(), entry.getValue());
			}
		}

		return message;
	}
}
